package com.example.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @program: SpringCloud-demo
 * @author: daPangDong
 * @create: 2022-05-25 16:48
 */
@Configuration
@EnableSwagger2
public class Knife4jConfiguration {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        String groupName="MyBatisGenerator版本";
        Docket docket=new Docket(DocumentationType.OAS_30)
                .apiInfo(getApiInfo())
                //分组名称
                .groupName(groupName)
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
//                .apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    /**
     * 配置基本信息
     */
    @Bean
    public ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档knife4j API 标题")
                .description("简介：# 记录服务端接口的入参，出参等信息")
                .termsOfServiceUrl("https://baidu.com")
                .contact(new Contact("逆流星", "https://baidu123.com","123@qq.com"))
                .version("3.12")
                .build();
    }


}